{{- define "snapshot_validation_resources" }}
cpu: 20m
memory: 50Mi
{{- end }}


{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: snapshot-validation-webhook
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "snapshot-validation-webhook" "workload-resource-policy.deckhouse.io" "master")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: snapshot-validation-webhook
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: "snapshot-validation"
      minAllowed:
        {{- include "snapshot_validation_resources" . | nindent 8 }}
      maxAllowed:
        cpu: 40m
        memory: 50Mi
{{- end }}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: snapshot-validation-webhook
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "snapshot-validation-webhook" )) | nindent 2 }}
spec:
  minAvailable: {{ include "helm_lib_is_ha_to_value" (list . 1 0) }}
  selector:
    matchLabels:
      app: snapshot-validation-webhook
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: snapshot-validation-webhook
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "snapshot-validation-webhook" )) | nindent 2 }}
spec:
  revisionHistoryLimit: 2
  {{- include "helm_lib_deployment_on_master_strategy_and_replicas_for_ha" . | nindent 2 }}
  selector:
    matchLabels:
      app: snapshot-validation-webhook
  template:
    metadata:
      labels:
        app: snapshot-validation-webhook
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/snapshot-validation-webhook/secret.yaml") . | sha256sum }}
    spec:
      imagePullSecrets:
        - name: deckhouse-registry
      {{- include "helm_lib_priority_class" (tuple . "system-cluster-critical") | nindent 6 }}
      {{- include "helm_lib_node_selector" (tuple . "master") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "any-node" "with-uninitialized") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_nobody" . | nindent 6 }}
      {{- include "helm_lib_pod_anti_affinity_for_ha" (list . (dict "app" "snapshot-validation-webhook")) | nindent 6 }}
      containers:
      - name: snapshot-validation
        {{- include "helm_lib_module_container_security_context_read_only_root_filesystem_capabilities_drop_all" . | nindent 8 }}
        args:
        - --tls-cert-file=/etc/snapshot-validation-webhook/certs/tls.crt
        - --tls-private-key-file=/etc/snapshot-validation-webhook/certs/tls.key
        - --port=4443
        image: {{ include "helm_lib_module_image" (list . "snapshotValidationWebhook") }}
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 4443
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_only_logs" . | nindent 12 }}
            {{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "snapshot_validation_resources" . | nindent 12 }}
            {{- end }}
        volumeMounts:
          - name: snapshot-validation-webhook-certs
            mountPath: /etc/snapshot-validation-webhook/certs
            readOnly: true
      volumes:
        - name: snapshot-validation-webhook-certs
          secret:
            secretName: snapshot-validation-webhook-certs
